package org.yefei.homeworkday20.one;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class ArraylistTest {

	public static void main(String[] args) {
		/*
		 * 1: 随机生成(Math.random()生成0-1之间的小数）10000个整数，放入ArrayList和LinkedList,比较时间。
		 * 1-2：从上面的集合中随机删除100个，比较时间。
		 */
		List list = new ArrayList();
		long start = System.nanoTime();
		for (int i = 1; i <= 10000; i++) {
			list.add((int) (Math.random() * 10000));
		}
		long end = System.nanoTime();
		System.out.println("ArrayList的插入元素的效率是：" + (end - start) + "纳秒");
		List list1 = new LinkedList();
		long start1 = System.nanoTime();
		for (int i = 1; i <= 10000; i++) {
			list1.add((int) (Math.random() * 10000));
		}
		long end1 = System.nanoTime();
		System.out.println("LinkedList的插入元素的效率是：" + (end1 - start1) + "纳秒");
		System.out.println(">>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<>>>>>>>>>>>><<<<<<<<<<<<<>>>>>>>>>><<<<<<<<<");
		long start2 = System.nanoTime();
		for (int i = 1; i <= 100; i++) {
			list.remove((int) (Math.random() * list.size()));
		}
		long end2 = System.nanoTime();
		System.out.println("ArrayList的删除元素的效率是：" + (end2 - start2) + "纳秒");
		long start3 = System.nanoTime();
		for (int i = 1; i <= 100; i++) {
			list1.remove((int) (Math.random() * list1.size()));
		}
		long end3 = System.nanoTime();
		System.out.println("LinkedList的删除元素的效率是：" + (end3 - start3) + "纳秒");
	}
}
